package com.qf.business.student.controller;

import com.qf.business.student.service.StudentService;
import com.qf.commons.base.result.R;
import com.qf.commons.base.result.Rs;
import com.qf.data.student.entity.Student;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * author Ken
 * create_time 2022/11/12
 */
@RestController
@RequestMapping("/stu")
@Slf4j
public class StuController {
    @Autowired
    private StudentService studentService;

    @Value("${com.name}")
    private String val;

    @RequestMapping("/list")
    public R list(String param){
        log.debug("[stu list] 查询学生列表 - {} - {}", param, val);
        List<Student> stus = studentService.list();
        return Rs.create(stus);
    }

    @RequestMapping("/insert")
    public R insert(@Validated Student student){
        studentService.save(student);
        return Rs.create();
    }

    /**
     * 根据id查询学生
     * @param id
     * @return
     */
    @RequestMapping("/queryById")
    public R queryById(Integer id){
        return Rs.create(studentService.getById(id));
    }
}
